---
title: "Business model of journals in Springer Nature"
output:
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    theme: spacelab
    source_code: embed
    fontsize: 16pt
---

```{js}
function filter_default() {
    document.getElementById("GENDER").getElementsByClassName("selectized") 
[0].selectize.setValue("both", false);
 }
$(document).ready(filter_default);
```

```{r setup}
library(knitr)
library(kableExtra)
library(flexdashboard)
library(WDI)
library(tidyverse)
library(plotly)
library(crosstalk)
library(ggthemes)
library(DT)
library(scales)
library(manipulateWidget); 

library(reactable)
library(lubridate)
library(hrbrthemes)
library(htmltools)
library(sparkline)
library(dplyr)
require(RJDBC)
require(rJava)
library(grid)
library(gridExtra)
library(sizeMat)
library(psych) 
library(extrafont)
library(ggplot2)

myfont="Times New Roman"
knitr::opts_chunk$set(echo = FALSE)

#source("C:/Users/momenifi/Dropbox/OASE/waiver/qss/plots.R",local = knitr::knit_global())
journal_model_field<-read.table("sn_journal_model_fied.csv",header=TRUE,sep=",",quote="\r",dec = ".")
journal_model_all<-read.table("sn_journal_model.csv",header=TRUE,sep=",",quote="\r",dec = ".")
sharedJournal_model_all<-SharedData$new(journal_model_all)
colors=c("grey","#C08DDF", "#FFD700","red")
plt_all<-plot_ly(data=journal_model_all,labels=~Model, values=~NUM_JOURNALS, type="pie",textinfo = "value",marker = list(colors = colors)) %>% 
    layout(title = list(text='Distrubtion of all journals by business model',font=list(
      size = 10
      )),
      legend = list(font = list(size=10)),
           width = 300, height = 300,
           xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
           yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))


sharedJournal_model_field<-SharedData$new(journal_model_field)
plt_field_journals<-
  ggplot(data=sharedJournal_model_field,aes(x=reorder(Model,desc(Model)), y=NUM_ITEMS,fill=Model )) +
  geom_col(position=position_dodge(), stat="identity",width=0.5,show.legend=FALSE) +
  scale_fill_manual(values=c("red","#FFD700", "#C08DDF"))+   
  theme_minimal()+
  labs(x="Scientific fields", y="Number of journals",#,
       caption = "(b)")+#"Percentage of articles published in journals 3 models across four groups of countries") +
  theme( text = element_text(family=myfont,size=24),
         axis.title.x=element_blank(),
         axis.title = element_text(face="bold"),
         plot.caption = element_text(hjust = 0),
         legend.title=element_text(face = "bold"),
         legend.text= element_text(face="plain"),
         axis.text  =  element_text( family=myfont,face = "bold"),
         axis.text.x=element_text(angle = 0))



ply_field_journals<-ggplotly(plt_field_journals,height=400)

bscols(widths = c(2,10,10),
       list(
         filter_select(id = "FIELD", label = "Field",
                       sharedData = sharedJournal_model_field, group = ~ FIELD,multiple=FALSE,allLevels = FALSE)
       ),plt_all,ply_field_journals
       )
  
  





```


```{css}
.crosstalk-input {
  margin-left: 15px;
}
```